package ru.eas.graph;

import java.util.*;

public class VertexDistance {

    public static void main(String[] args) {
        String testString = "4 4\n" +
                "1 2\n" +
                "4 1\n" +
                "2 3\n" +
                "3 1\n" +
                "2 4";
        Scanner scanner = new Scanner(testString);

//        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int m = scanner.nextInt();
        UndirectedGraph graph = new UndirectedGraph(n);
        for (int i = 0; i < m; i++) {
            graph.addEdge(scanner.nextInt(), scanner.nextInt());
        }
        int vertex1 = scanner.nextInt();
        int vertex2 = scanner.nextInt();
        System.out.println(graph.distance(vertex1, vertex2));
    }

    static class UndirectedGraph {
        public static final int INFINITY_DISTANCE = -1;

        private List<List<Integer>> vertices;

        private int[] distances;

        public UndirectedGraph(int vertexCount) {
            vertexCount++;
            vertices = new ArrayList<List<Integer>>(vertexCount);
            for (int i = 0; i < vertexCount; i++) {
                vertices.add(new ArrayList<Integer>());
            }
            distances = new int[vertexCount];
        }

        public void addEdge(int vertex1, int vertex2) {
            vertices.get(vertex1).add(vertex2);
            vertices.get(vertex2).add(vertex1);
        }

        private void bfs(int vertex) {
            for (int i = 1; i < vertices.size(); i++) {
                distances[i] = INFINITY_DISTANCE;
            }
            distances[vertex] = 0;
            Queue<Integer> queue = new LinkedList<Integer>();
            queue.add(vertex);
            while (!queue.isEmpty()) {
                int vertex1 = queue.poll();
                for (int vertex2 : vertices.get(vertex1)) {
                    if (distances[vertex2] == INFINITY_DISTANCE) {
                        queue.add(vertex2);
                        distances[vertex2] = distances[vertex1] + 1;
                    }
                }
            }
        }

        public int distance(int vertex1, int vertex2) {
            bfs(vertex1);
            return distances[vertex2];
        }
    }
}
